<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名字" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="classes">
        <el-input
          v-model="queryParams.classes"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="校区" prop="campus">
        <el-input
          v-model="queryParams.campus"
          placeholder="请输入校区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择学生状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_student_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:student:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['student:student:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['student:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleTypeUpdate"
          v-hasPermi="['student:student:typeUpdate']"
        >状态修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh"
          size="mini"
          :disabled="multiple"
          @click="handleRepeated"
        >转班</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-edit-outline"
          size="mini"
          :disabled="multiple"
          @click="handleTrace"
          v-hasPermi="['student:student:trace']"
        >添加跟踪</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:student:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="名字" align="center" prop="studentName" />
      <el-table-column label="班级" align="center" prop="classes" />
      <el-table-column label="校区" align="center" prop="campus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_campus_type" :value="scope.row.campus"/>
        </template>
      </el-table-column>
      <el-table-column label="学生状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_student_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="模拟面试" align="center" prop="mockInterview">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_mock_interview" :value="scope.row.mockInterview"/>
        </template>
      </el-table-column>
      <el-table-column label="结业考试" align="center" prop="finalTest">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_final_test" :value="scope.row.finalTest"/>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="180px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-set-up"
            @click="handleTraceHistory(scope.row)"
          >跟踪</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetails(scope.row)"
            v-hasPermi="['student:student:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-star-on"
            @click="handleFocus(scope.row)"
          >关注</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['student:student:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['student:student:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名字" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入名字" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio label="0">男</el-radio>
            <el-radio label="1">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="校区">
          <el-select v-model="form.campusId"
                     @change="campusHandleChange"
                     placeholder="校区">
            <el-option
              v-for="item in campusList"
              :key="item.id"
              :label="item.campusName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学科">
          <el-select v-model="form.subjectId" @change="subjectHandleChange" placeholder="学科">
            <el-option
              v-for="item in subjectsList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班级">
          <el-select v-model="form.classes" placeholder="班级">
            <el-option
              v-for="item in classesList"
              :key="item.className"
              :label="item.className"
              :value="item.className"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="专业" prop="speciality">
          <el-input v-model="form.speciality" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校" />
        </el-form-item>
        <el-form-item label="父母电话" prop="parentPhone">
          <el-input v-model="form.parentPhone" placeholder="请输入父母电话" />
        </el-form-item>
        <el-form-item label="学生状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="mockInterview">
          <el-select v-model="form.mockInterview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_mock_interview"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业考试" prop="finalTest">
          <el-select v-model="form.finalTest" placeholder="请选择结业考试">
            <el-option
              v-for="dict in dict.type.sys_final_test"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看详情对话框 -->
    <el-dialog :title="title" :visible.sync="openDetails" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="ID" prop="id">
              <template>
                <span>{{form.id}}</span>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名字" prop="studentName">
              <template>
                <span>{{form.studentName}}</span>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <template>
                <span v-if="form.sex == 0" >男</span>
                <span v-else-if="form.sex == 1" >女</span>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <template>
                <span>{{form.age}}</span>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="班级" prop="classes">
              <template>
                <span>{{form.classes}}</span>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话" prop="phone">
              <template>
                <span>{{form.phone}}</span>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="校区" prop="campus">
              <template>
                <dict-tag :options="dict.type.sys_campus_type" :value="form.campus"/>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生状态" prop="status">
              <template>
                <dict-tag :options="dict.type.sys_student_status" :value="form.status"/>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="模拟面试" prop="mockInterview">
              <template>
                <dict-tag :options="dict.type.sys_mock_interview" :value="form.mockInterview"/>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结业考试" prop="finalTest">
              <template>
                <dict-tag :options="dict.type.sys_final_test" :value="form.finalTest"/>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="education">
              <template>
                <span>{{form.education}}</span>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业" prop="speciality">
              <template>
                <span>{{form.speciality}}</span>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学校" prop="school">
              <template>
                <span>{{form.school}}</span>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="父母电话" prop="parentPhone">
              <template>
                <span>{{form.parentPhone}}</span>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 批量修改状态对话框 -->
    <el-dialog :title="title" :visible.sync="openTypeUpdate" width="500px" append-to-body>
      <el-form ref="form" :model="typeParams" :rules="rules" label-width="80px">
        <el-form-item label="学生状态" prop="status">
          <el-select v-model="typeParams.status" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="mockInterview">
          <el-select v-model="typeParams.mockInterview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_mock_interview"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业考试" prop="finalTest">
          <el-select v-model="typeParams.finalTest" placeholder="请选择结业考试">
            <el-option
              v-for="dict in dict.type.sys_final_test"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTypeParams">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加跟踪对话框 -->
    <el-dialog :title="title" :visible.sync="openTrace" width="500px" append-to-body>
      <el-form ref="form" :model="traceParams" :rules="rules" label-width="80px">
        <el-form-item label="问题类型" prop="questionType">
          <el-select v-model="traceParams.questionType" placeholder="请选择问题类型" style="width: 100%">
            <el-option
              v-for="dict in dict.type.sys_question_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间" prop="happenTime">
          <el-date-picker clearable
                          v-model="traceParams.happenTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择发生时间" style="width: 100%">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="扣除分数" prop="deductPoints">
          <el-input v-model="traceParams.deductPoints" placeholder="请输入扣分" />
        </el-form-item>
        <el-form-item label="问题描述" prop="remark">
          <el-input v-model="traceParams.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTrace">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--上传界面-->
    <el-dialog title="上传学生" :visible.sync="importFormVisible" :close-on-click-modal="false">
      <el-form :model="importForm" label-width="80px" ref="importForm">
        <el-form-item>
          <el-button @click="handleExportTemplate" type="primary">下载模板</el-button>
        </el-form-item>
        <el-form-item>
          <el-upload
            class="upload-demo"
            :action="url"
            multiple
            :limit="1"
            :headers="headers"
            :on-success="ExcelImportSuccess"
            :file-list="fileList">
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 跟踪记录 -->
    <el-dialog :title="title" :visible.sync="traceHistoryVisible" width="500px">
      <div class="block">
        <el-timeline>
          <el-timeline-item  v-for="item in traceFocusList" :timestamp="item.createTime" placement="top" :color="getColor(item)">
            <el-card>
              <h4>跟踪人[{{item.teacherName}}]</h4>
              <p>问题说明：{{item.remark}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 添加留级学生 -->
    <el-dialog :title="title" :visible.sync="repeatedVisible" width="500px">
      <el-form ref="form" :model="traceParams" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="studentName">
          <el-input v-model="repeatedParams.studentName" readonly/>
        </el-form-item>
        <el-form-item label="转入班级" prop="classes">
          <el-select v-model="repeatedParams.className" placeholder="请选择问题类型" style="width: 100%">
            <el-option
              v-for="classes in sameCampusClassList"
              :key="classes.className"
              :label="classes.className"
              :value="classes.className">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负责老师" prop="teacherName">
          <el-select v-model="repeatedParams.teacherName"
                     @change="onTeacherSelected"
                     placeholder="请选择负责老师" style="width: 100%">
            <el-option
              v-for="teacher in teacherList"
              :key="teacher.name"
              :label="teacher.name"
              :value="teacher.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生状态" prop="status">
          <el-select v-model="repeatedParams.status" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="repeatedParams.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="submitRepeated">确 认</el-button>
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStudent,
  getStudent,
  delStudent,
  addStudent,
  updateStudent,
  patchTypeUpdate,
  treeData,
  addStudentFocus, getCampusList, repeatedChange
} from "@/api/student/student";
import {addTrace, listTrace} from "@/api/teaching/trace";
import {getToken} from "@/utils/auth";
import {getClassByCampus, listClass} from "@/api/student/class";
import {listCampus, listSubjects, listTeacher, listTeacherType, loadSuperiorsObjs} from "@/api/teacher/teacher";
import {addRepeatedStudents} from "@/api/teaching/repeatedStudents";

export default {
  name: "Student",
  dicts: ['sys_mock_interview', 'sys_student_status', 'sys_final_test','sys_campus_type','sys_question_type'],
  data() {
    return {
      // 上传文件
      url: process.env.VUE_APP_BASE_API + "/student/student/import",
      headers: {Authorization: "Bearer " + getToken()},
      fileList: [],
      importForm: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生管理表格数据
      studentList: [],
      // 多选学生列表
      selectionStudentList: [],
      // 跟踪列表
      traceList: [],
      // 班级列表
      classList: [],
      // 老师列表
      teacherList: [],
      // 跟踪记录
      traceFocusList: [],
      // 校区列表
      campusList: [],
      // 学科列表
      subjectsList: [],
      // 学科对应班级列表
      classesList: [],
      // 对应校区的班级列表
      sameCampusClassList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openDetails: false,
      openTypeUpdate: false,
      openTrace: false,
      importFormVisible: false,
      traceHistoryVisible: false,
      repeatedVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: null,
        classes: null,
        campus: null,
        status: null,
        phone: null,
      },
      // 批量修改状态参数
      typeParams: {
        status: null,
        mockInterview: null,
        finalTest: null,
      },
      // 添加跟踪参数
      traceParams: {
        className: null,
        studentName: null,
        questionType: null,
        deductPoints: null,
        traceTimes: null,
        teacherName: null,
        remark: null,
        deleted: null,
        updateTime: null,
        classId: null,
        studentId: null,
        teacherId: null,
        happenTime: null
      },
      // 添加留级学生参数
      repeatedParams: {
        studentId: null,
        studentName: null,
        className: null,
        status: null,
        remark: null,
        mockInterview: null,
        finalTest: null,
        classId: null,
        teacherId: null,
        teacherName: null,
        difficultyCoefficient: 0,
      },
      // 班级对应校区表单
      campusClassForm: {
        id: null,
        campusClass: '',
        parentId: '',
        studentId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getTraceList();
    this.getClassList();
    this.getListCampus();
    this.getTeacherList();
  },
  methods: {
    /** 查询老师列表 */
    getTeacherList() {
      this.loading = true;
      listTeacher(this.queryParams).then(response => {
        this.teacherList = response.rows;
        this.loading = false;
      });
    },
    /** 查询学生管理列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询班级列表 */
    getClassList() {
      this.loading = true;
      listClass(this.queryParams).then(response => {
        this.classList = response.rows;
        this.loading = false;
      });
    },
    /** 查询跟踪列表 */
    getTraceList() {
      this.loading = true;
      listTrace(this.queryParams).then(response => {
        this.traceList = response.rows;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openTypeUpdate = false;
      this.openTrace = false;
      this.traceHistoryVisible = false;
      this.repeatedVisible = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        studentName: null,
        sex: null,
        classes: null,
        campus: null,
        status: null,
        mockInterview: null,
        finalTest: null,
        phone: null,
        age: null,
        education: null,
        speciality: null,
        school: null,
        parentPhone: null,
        version: null,
        campusId:null,
        classId:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectionStudentList = []
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
      this.selectionStudentList.push(selection);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生管理";
    },
    /** 添加跟踪操作 */
    handleTrace() {
      this.reset();
      this.openTrace = true;
      this.title = "添加学生管理";
    },
    /** 详情按钮操作 */
    handleDetails(row) {
      this.reset();
      const id = row.id || this.ids
      getStudent(id).then(response => {
        this.form = response.data;
        this.openDetails = true;
        this.title = "学生信息详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStudent(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学生管理编号为"' + ids + '"的数据项？').then(function() {
        return delStudent(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 状态修改按钮 */
    handleTypeUpdate() {
      this.reset();
      this.openTypeUpdate = true;
      this.title = "批量修改状态";
    },
    /** 确认提交批量修改状态按钮 */
    submitTypeParams() {
      const typeParams = this.typeParams;
      this.openTypeUpdate = false;
      this.selectionStudentList.forEach(ssl => {
        ssl.status = typeParams.status;
        ssl.mockInterview = typeParams.mockInterview;
        ssl.finalTest = typeParams.finalTest;
      })
      /** 批量修改状态方法 */
      patchTypeUpdate(this.selectionStudentList).then(() => {
        this.getList();
        this.$modal.msgSuccess("修改成功");
      })
    },
    /** 确认提交添加跟踪按钮 */
    submitTrace() {
      const traceParams = this.traceParams;
      this.openTrace = false;
      this.selectionStudentList.forEach(ssl => {
        traceParams.className = ssl.className;
        traceParams.studentName = ssl.studentName;
        traceParams.teacherName = ssl.charge;
        /** 添加跟踪方法 */
        addTrace(traceParams).then(() => {
          this.getList();
          this.$modal.msgSuccess("添加成功");
        })
      })
    },
    /** 下载模版操作 */
    handleExportTemplate() {
      this.download('student/student/exportTemplate', {
        ...this.queryParams
      }, `student_${new Date().getTime()}.xlsx`)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('student/student/export', {
        ...this.queryParams
      }, `student_${new Date().getTime()}.xlsx`)
    },
    /** 文件导入 */
    handleImport() {
      this.importFormVisible = true;
    },
    ExcelImportSuccess(file) {
      if (file.code==200) {
        this.$message.success('导入成功');
        this.importFormVisible = false;
        this.getList();
        this.fileList = [];
      } else {
        this.$message.error(file.message);
      }
    },
    /** 给跟踪记录的时间戳赋颜色 */
    getColor(item){
      let _this = this;
      if(item.traceTimes === _this.traceFocusList.length){
        return '#0BBD87';
      } else {
        return '#EE1118';
      }
    },
    /** 跟踪记录 */
    handleTraceHistory(row){
      let _this = this;
      _this.traceHistoryVisible = true;
      _this.title = '[' + row.studentName + ']的跟踪历史';
      this.campusClassForm.studentId = row.id;
      listTrace(this.campusClassForm).then(response => {
        _this.traceFocusList = response.rows;
      });
    },
    /** 添加关注 */
    handleFocus(row) {
      const id = row.id;
      this.$modal.confirm('是否确认将编号为' + id + '的学生添加到关注列表？').then(function() {
        return addStudentFocus(row);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("添加关注成功");
      }).catch(() => {});
    },
    /** 根据选择的老师，把老师id加入repeatedParams中 */
    onTeacherSelected(selectedTeacherName){
      this.teacherList.forEach(tl => {
        if (tl.name == selectedTeacherName){
          this.repeatedParams.teacherId = tl.id;
        }
      });
    },
    /** 确认添加留级转班学生 */
    handleRepeated() {
      const repeatedParams = this.repeatedParams;
      this.selectionStudentList[0].forEach(ssl => {
        repeatedParams.studentName = ssl.studentName;
        repeatedParams.studentId = ssl.id;
        repeatedParams.className = ssl.classes;
        repeatedParams.classId = ssl.classId;
        repeatedParams.status = 1;
        repeatedParams.studentId = ssl.id;
        repeatedParams.finalTest = ssl.finalTest;
        repeatedParams.mockInterview = ssl.mockInterview;
        //根据选择学生的校区返回该校区内所有的班级
        getClassByCampus(ssl.campus).then(response => {
          this.sameCampusClassList = response.rows;
        });
      })
      console.log(repeatedParams)
      this.reset();
      this.title = '[' + repeatedParams.studentName + '] 转班处理';
      this.repeatedVisible = true;
    },
    /** 确认添加留级转班学生*/
    submitRepeated() {
      this.repeatedVisible = false;
      repeatedChange(this.repeatedParams);
      addRepeatedStudents(this.repeatedParams).then(() => {
        this.getList();
        this.$modal.msgSuccess("已为学生办理留级转班");
      })
    },
    //选中校区获取学科
    campusHandleChange(res) {
      for (let i = 0; i < this.campusList.length; i++) {
        if (this.campusList[i].id == res) {
          this.subjectsList = this.campusList[i].subjects;
          this.form.campus = this.campusList[i].campusName;
          return;
        }
      }
    },
    //选中学科获取班级
    subjectHandleChange(res) {
      for (let i = 0; i < this.subjectsList.length; i++) {
        if (this.subjectsList[i].id == res) {
          this.classesList = this.subjectsList[i].classes;
          if (this.subjectsList[i].classes.length == 0) {
            continue;
          }
          this.form.classId = this.subjectsList[i].classes[i].id;
          return;
        }
      }
    },
    //查询校区
    getListCampus() {
      getCampusList().then(res => {
        let {code, rows} = res;
        if (code == 200) {
          this.campusList = rows;
        }
      })
    },
  }
};
</script>
